<?php
namespace app\admin\controller;

use app\common\model\LuntanArticle  as ArticleModel;
use app\common\model\LuntanCategory as CategoryModel;
use app\common\model\LuntanReply    as ReplyModel;
use app\common\model\User           as UserModel;
use app\common\controller\AdminBase;
use think\Session;

/**
 * 文章管理
 * Class Article
 * @package app\admin\controller
 */
class LuntanReply extends AdminBase
{
    protected $article_model;
    protected $category_model;

    protected function _initialize()
    {
        parent::_initialize();
        $this->article_model  = new ArticleModel();
        $this->category_model = new CategoryModel();
        $this->reply_model    = new ReplyModel();
        $this->user_model     = new UserModel();
        $category_level_list = $this->category_model->getLevelList();
        $this->assign('category_level_list', $category_level_list);
    }

     /**
     * 评论管理
     * @param int    $cid     分类ID
     * @param string $keyword 关键词
     * @param int    $page
     * @return mixed
     */
    public function index($cid = 0, $keyword = '', $page = 1)
    {
        $replylist     = $this->reply_model->getReplyList($cid,$keyword,$page);
        $articlelist   = $this->article_model->column('title', 'id');
        $category_list = $this->category_model->column('name', 'id');
        $userlist      = $this->user_model->column('username','id');
        return $this->fetch('index', ['cid' => $cid, 'keyword' => $keyword,'replylist'=>$replylist,'articlelist'=>$articlelist,'category_list'=>$category_list,'userlist'=>$userlist]);
    }

    /**
     * 删除回帖
     * @param int   $id
     * @param array $ids
     */
    public function delete($id = 0, $ids = [])
    {
        $this->delete3($id,$ids,$model = "reply_model");
    }

    
    // /**
    //  * 编辑文章
    //  * @param $id
    //  * @return mixed
    //  */
    // public function edit($id)
    // {
    //     $article = $this->reply_model->find($id);
    //     if($article['photo']){
    //         $article['photo'] = getphoto($article['photo']);
    //     }
    //     return $this->fetch('edit', ['article' => $article]);
    // }

    // /**
    //  * 更新文章
    //  * @param $id
    //  */
    // public function update($id)
    //  {
    //     if ($this->request->isPost()) {
    //         $data            = $this->request->param();
    //         $validate_result = $this->validate($data, 'LuntanArticle');
    //         if(array_key_exists('photo', $data)){
    //             $data['photo'] = setphoto($data['photo']);
    //         }
    //         if ($validate_result !== true) {
    //               $this->error($validate_result);
    //         } else {
    //             if ($this->article_model->allowField(true)->save($data, $id) !== false) {
    //                 $this->success('更新成功');
    //             } else {
    //                $this->error('更新失败');
    //             }
    //         }
    //     }
    // }


}